CFLAGS := $(CFLAGS)  -pedantic
LDFLAGS := -lm $(LDFLAGS)
CXX= g++

#define OUTPUT_STATISTICS 
#define USE_MATLAB
# efine USE_THREADS 

# add ANN library 
CFLAGS := -gdwarf-2 -I/home/nouri/codes/libs/ $(CFLAGS)
LDFLAGS := -L/home/nouri/codes/libs/originals/ann_1.1.1/lib  -lANN   $(LDFLAGS)



#ifdef USE_THREADS
BOOST_ROOT := /home/nouri/codes/libs/boost_1_39_0
CFLAGS := $(CFLAGS) -I$(BOOST_ROOT)
LDFLAGS := $(LDFLAGS) -L$(BOOST_ROOT)/lib/ -lboost_date_time-gcc41-mt-1_39 -lboost_thread-gcc41-mt-1_39
#endif

#ifdef USE_MATLAB 
MATLAB_ROOT := /usr/local/matlab
CFLAGS := $(CFLAGS) -I$(MATLAB_ROOT)/extern/include
LDFLAGS := $(LDFLAGS) -L$(MATLAB_ROOT)/bin/glnxa64 -lmx -lmex -lmat -leng
#endif

BINARY = mre_agent


AGENTSRC = AgentProxy.cpp KNNSimpleGeneralizer.cpp MahalanobisMetricLearner.cpp PLSMetricLearner.cpp MREAgent.cpp GridSolver.cpp TFGenerator.cpp Grid.cpp KDTree.cpp KDTreeLearner.cpp KNode.cpp LocalRegression.cpp MDPSolver.cpp OriginalRewardGenerator.cpp OriginalTFGenerator.cpp ParamReader.cpp RFGeneralizer.cpp Util.cpp GenericMessage.cpp ValueFunctionRequestMessage.cpp ValueFunctionResponseMessage.cpp MatlabDrawer.cpp MatlabMatrix.cpp FMLKRGeneralizer.cpp SimpleTFGeneralizer.cpp  MatlabInterface.cpp Regressor.cpp MetricLearner.cpp FittedVISolver.cpp UCTBackuper.cpp UCTSolver.cpp 
AGENTOBJ = $(addprefix Build/, $(addsuffix .o, $(basename $(AGENTSRC))))

#ENV = MetricTesterEnv.cpp
#ENV = ../../env/BumbleBallSim/BumbleBallSim.cpp 
ENV  = ../../env/Puddleworld/PuddleWorld.cpp
#ENV = ../../env/MountainCar/MountainCar.cpp
#ENV = ../../env/Acrobot/acrobot.cpp 

ENVOBJ = $(addsuffix .o, $(basename $(ENV))) 

all: $(AGENTOBJ) $(ENVOBJ)  Build/main.o 
	@echo "--------------------Link section---------------------"
	${CXX}  $^ $(LDFLAGS)  -lrlutils -lrlagent -o $(BINARY)

$(ENVOBJ): $(ENV)
	${CXX} $(CFLAGS) -o $(ENVOBJ) -c $(ENV)
	
network: $(AGENTOBJ) $(ENVOBJ) 
	${CXX} $^   $(LDFLAGS) -lrlutils -lrlagent -lrlgluenetdev -o $(BINARY)

Build/%.o: %.cpp
	${CXX}  $(CFLAGS) -o $@  -c $<


clean:
	rm -rf $(BINARY) core* Build/*.o

kill: 
	killall -9 $(BINARY)
run:
	./$(BINARY) 127.0.0.1 4096 > result.out & 
	tailf result.out | grep episode 

